package com.yunfei.procedure;

import com.yunfei.api.v2.param.heTongLuRu.HeTongLuRuParam;
import com.yunfei.utils.jdbc.AiiidbUtil;
import oracle.jdbc.OracleTypes;

import java.sql.*;

/**
* @Description: 系统自动提交合同信息
* @Author: zhengyunfei
* @Date: 2019/2/15
* @time:16:44
*/
public class GetContractNoProcedure {
    private Connection conn;
    private CallableStatement stat;
    private ResultSet rs;
    String cllSql = "call SP_ELEC_CONT_CON_NO(?,?,?)";
    /**
    * @Description: 获取合同编号
    * @Author: zhengyunfei
    * @Date: 2018/4/24
    * @time:13:49
    */
    public ProcedureResultModel callProcedure(AiiidbUtil aiiidbUtil, String projId) {
        ProcedureResultModel result=new ProcedureResultModel();

        try {
            String url=aiiidbUtil.getJdbcUrl();
            String driverName=aiiidbUtil.getDriveClassName();
            String username=aiiidbUtil.getJdbcUserName();
            String password=aiiidbUtil.getJdbcPassword();
            Class.forName(driverName);
            conn = DriverManager.getConnection(url, username, password);
            stat = conn.prepareCall(cllSql);
            stat.setString(1, projId);//输入
            stat.registerOutParameter(2, OracleTypes.VARCHAR);//输出
            stat.registerOutParameter(3, OracleTypes.VARCHAR);//输出
            stat.execute();
            String returnCode= stat.getString(2);//处理结果 0:失败 1成功
            String returnInfo= stat.getString(3);//处理结果描述
            result.setReturnCode(returnCode);
            result.setReturnInfo(returnInfo);
            System.out.println("合同信息录入存储过程返回结果: " + result);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            close(conn, stat, rs);
        }
        return result;
    }

    // 关闭连接
    public void close(Connection conn, CallableStatement stat, ResultSet rs) {
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                rs = null;
            }
        }
        if (stat != null) {
            try {
                stat.close();
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                stat = null;
            }
        }
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                conn = null;
            }
        }
    }

    public static void main(String[] args) {
       // new GetTouZiZheRenZhengInfoProcedure().callProcedure("20180417132146779447466");
    }
}